
function checkButtonsState() {
    var leftSelected = document.getElementById('leftBox').getElementsByClassName('selected').length > 0;
    var rightSelected = document.getElementById('rightBox').getElementsByClassName('selected').length > 0;
    document.getElementById('toRightButton').disabled = !leftSelected;
    document.getElementById('toLeftButton').disabled = !rightSelected;
}

var leftBox = document.getElementById('leftBox');
var rightBox = document.getElementById('rightBox');

leftBox.addEventListener('click', function(event) {
    var selected = event.target;
    if (selected.nodeName === 'LI') {
        selected.classList.toggle('selected');
        checkButtonsState();
    }
});

rightBox.addEventListener('click', function(event) {
    var selected = event.target;
    if (selected.nodeName === 'LI') {
        selected.classList.toggle('selected');
        checkButtonsState(); // 检查按钮状态
    }
});
